/**
 * Created by admin on 2018/1/11.
 */
import {config, sandBox} from '../../../lib/myapp.js';
Page({

    data: {
        order_refund: {},
        refund_no: 'O2018011181119858738'
    },

    onLoad(e){
        if (e.refund_no) {
            this.setData({
                refund_no: e.refund_no
            })
        } else {
            wx.navigateBack()
        }
    },

    onShow(){
        wx.showLoading({
            mask: true
        })
        var refund_no = this.data.refund_no
        var oauth = wx.getStorageSync('user_token')
        sandBox.get({
            api: `api/O2O/refund/show/${refund_no}`,
            header: {Authorization: oauth},
        }).then(res => {

            res = res.data
            if (res.data) {

                var item_meta = res.data.order_item.item_meta
                item_meta.color = item_meta.specs_text.split(' ')[0]
                item_meta.size = item_meta.specs_text.split(' ')[1]
                this.setData({
                    order_refund: res.data
                })
            } else {
                wx.showModal({
                    content: res.message || '获取接口数据失败',
                    showCancel: false
                })
            };

            wx.hideLoading();
        }).catch(() => {
            wx.showModal({
                content: '服务端出错',
                showCancel: false
            })

            wx.hideLoading();
        })
    },

    submit(){
        var refund_no = this.data.refund_no
        var oauth = wx.getStorageSync('user_token')
        sandBox.post({
            api: `api/O2O/refund/refundProcessor`,
            header: {Authorization: oauth},
            data: {
                refund_no: refund_no
            }
        }).then(res => {
            res = res.data
            if (res.code == 200 && res.data) {
                wx.redirectTo({
                    url: '/pages/order/index/index'
                })
            } else {
                wx.showModal({
                    content: res.message || '获取接口数据失败',
                    showCancel: false
                })
            }
        }).catch(() => {
            wx.showModal({
                content: '服务端出错',
                showCancel: false
            })

        })
    }
})